home *** CD-ROM | disk | FTP | other *** search
/ Plug-In Power Pack for Netscape Communicator / Plug-In Power Pack for Netscape Communicator.iso / plugins / dataviews / dvtools / examples / programs / win_multi.c < prev   
Encoding:
C/C++ Source or Header  |  1997-05-08  |  13.0 KB  |  383 lines

  1. #ifndef lint
  2. static char SccsId[]= "@(#)win_multi.c    V1.21    3/13/95";
  3. #endif
  4. /*
  5. |    file name - win_multi.c
  6. |===================================================================
  7. |
  8. |    This program demonstrates multiple window event gathering.
  9. |
  10. |    This program demonstrates how to use the window event
  11. |       routines to gather events from multiple windows.  It uses
  12. |    VOloWinEventPoll, which gets the next event from the queue,
  13. |    regardless of which window it came from. Also, it shows how
  14. |    a typical application might respond to some event types
  15. |    such as V_RESIZE, V_EXPOSE, and V_WINDOW_QUIT.
  16. |
  17. |    Events are passed to the event request handler so the input
  18. |    objects will update. The graphs are updated only if the input
  19. |    object took user input. In addition, this example shows how
  20. |       to specify the dimensions and name of a window created using
  21. |    TscOpenSet.
  22. |
  23. |    In order to see a summary of the events on standard output
  24. |    as they occur, rename the executable "win_eventsdb.x" and
  25. |    invoke it from the command line.
  26. |
  27. |    Generate a window QUIT event or type <q|Q> to exit.
  28. |
  29. |===================================================================
  30. */
  31. #include <windows.h>
  32. /*
  33.  *  DV-Tools header files
  34.  */
  35. #include "std.h"                /* <stdio.h> etc., scalar & macro definitions */
  36. #include "dvstd.h"              /* public types & constants */
  37. #include "dvtools.h"            /* constants used by T routines */
  38. #include "dvGR.h"               /* constants used by window mgt & GR routines */
  39. #include "VOstd.h"              /* constants used by VO & VOob routines */
  40. #include "Tfundecl.h"           /* T routines (screens, drawports & views) */
  41. #include "VOfundecl.h"          /* VO routines (objects) */
  42. #include "VUerfundecl.h"        /* VUer routines (event handling routines) */
  43. #include "GRfundecl.h"          /* GR routines (interface to display device) */
  44. #include "VUfundecl.h"          /* VU routines (utilities) */
  45.  
  46. /* Constants */
  47. #define  DVPATH            (char *)NULL
  48. #define  DISPFORMS_STB     (char *)NULL
  49. #define  DVDEVICE          (char *)NULL
  50. #define  DVCOLORTABLE      (char *)NULL
  51. #define  SCREEN_VIEWPORT   (RECTANGLE *)NULL
  52. #define  DRAWING_VIEWPORT  (RECTANGLE *)NULL
  53. #define  WIN_MULTI_DBG       "win_multidb.x"
  54. #define  MAXWINS       (int)2
  55.  
  56. /* Define local variable containing view names and local funcation */
  57. char *view_name[MAXWINS] =
  58. {"multi1.v", "multi2.v"};
  59.  
  60. /* Functions defined in win_multi.c */
  61. LOCAL ADDRESS drawnext_if_screen V_P_((DRAWPORT drawport, ADDRESS screen));
  62. /***************** End Function Declarations *************/
  63.  
  64.  
  65. /*
  66.  *   MAIN PROGRAM
  67.  */
  68. int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  69.                      LPSTR lpCmdLine,  int nCmdShow  )
  70. {
  71.   INT argc = 0;
  72.   CHAR **argv;
  73.  
  74.   /*
  75.    *  program arguments
  76.    *    argv[1] - display device (default is DVDEVICE)
  77.    */
  78.  
  79.   /* Define & initialize device name */
  80.   char *device_name = DVDEVICE; /* default device name */
  81.  
  82.   /* Define display variables */
  83.   OBJECT screen[MAXWINS];       /* display device, the window */
  84.   DRAWPORT drawport[MAXWINS];   /* how & where to display picture */
  85.   VIEW view[MAXWINS];           /* picture representation of the view file */
  86.  
  87.   /* Control loop variables */
  88.   OBJECT location,              /* the event representation */
  89.     current_screen;             /* current selected screen */
  90.   WINEVENT *we;                 /* structure storing details of event */
  91.   int event_req_status;         /* status of event requests */
  92.  
  93.   /* Other variables */
  94.   int screenx,                  /* new width of window in pixels */
  95.     screeny,                    /* new height of window in pixels */
  96.     i;                          /* index counter */
  97.   int Quit = NO;                /* flag to quit program */
  98.  
  99.  
  100.   /*-----------------
  101.    *   Initialization
  102.    *
  103.    *   TInit:    perform the initialization of DV-Tools
  104.    *             TInit reads your configuration file and any
  105.    *             environment variables or logical names set.
  106.    */
  107.   make_argv(&argc,&argv,GetCommandLine());
  108.   TInit( DVPATH, DISPFORMS_STB );
  109.  
  110.   if (argc > 1)
  111.     device_name = argv[1];
  112.   for (i = 0; i < MAXWINS; i++)
  113.     {
  114.       /*
  115.        *   TscOpenSet:  opens a device as a screen object using
  116.        *                specified attributes
  117.        *
  118.        *   Set exposure block to YES to insure the window is
  119.        *   ready for drawing when TdpDraw is called.
  120.        */
  121.       screen[i] = TscOpenSet (device_name, DVCOLORTABLE,
  122.                               V_WINDOW_WIDTH, 400,
  123.                               V_WINDOW_HEIGHT, 300,
  124.                               V_WINDOW_NAME, "win_multi",
  125.                               V_WINDOW_X, 150 * i,
  126.                               V_WINDOW_Y, i * 100,
  127.                               V_X_EXPOSURE_BLOCK, YES,
  128.                               V_ACTIVE_CURSOR,
  129.                               V_END_OF_LIST);
  130.       if (!screen[i])
  131.         {
  132.           printf ("Must specify device on command line or");
  133.           printf (" in DataViews configuration file.\n");
  134.           S_EXIT (EXIT_ERR);
  135.         }
  136.  
  137.       /*
  138.        *   VOscWinEventMask:  sets the screen's window event mask
  139.        */
  140.       VOscWinEventMask ((ULONG) V_KEYPRESS | V_KEYRELEASE |
  141.                                 V_BUTTONPRESS | V_BUTTONRELEASE |
  142.                                 V_ENTERNOTIFY | V_MOTIONNOTIFY | V_LEAVENOTIFY |
  143.                                 V_EXPOSE | V_RESIZE | V_WINDOW_QUIT,
  144.             (ULONG) 0);
  145.       /*
  146.        *   TviLoad:   Load a view in from a file,
  147.        *              user supplied view or default view
  148.        *   TdpCreate: Create a drawport.
  149.        *              The drawport is attached to the screen object
  150.        *              specified while view specifies the view to be
  151.        *              displayed on the screen.
  152.        */
  153.       view[i] = TviLoad (view_name[i]);
  154.       if (!view[i])
  155.         {
  156.           printf ("Could not load view from file ");
  157.           printf ("%s.\n", view_name[i]);
  158.           if (i == 0)
  159.             TscClose (screen[0]);
  160.           else
  161.             {
  162.               TdpDestroy (drawport[0]);
  163.               TviDestroy (view[0]);
  164.               TscClose (screen[0]);
  165.               TscClose (screen[1]);
  166.             }
  167.           S_EXIT (EXIT_ERR);
  168.         }
  169.       drawport[i] = TdpCreate (screen[i], view[i],
  170.                                SCREEN_VIEWPORT, DRAWING_VIEWPORT);
  171.  
  172.       /*
  173.        *   TscErase: Erase the entire screen in the default
  174.        *             background color
  175.        *   TdpDraw:  Draw the contents of the drawport
  176.        */
  177.       TscErase (screen[i]);
  178.       TdpDraw (drawport[i]);
  179.     }
  180.  
  181.   /*--------------------
  182.    *   Control loop
  183.    *
  184.    *   Poll the event queue for window events specified by the
  185.    *   window mask in either of the screens. Set the current
  186.    *   screen based on where the event happened.  Handle each
  187.    *   of the events as they happen. Events occurring within
  188.    *   input objects will be handled through the event request
  189.    *   handler VUerHandleLocEvent. Updates are performed if an
  190.    *   input object used the event.
  191.    */
  192.   FOREVER
  193.   {
  194.     /*
  195.      *  VOloWinEventPoll:  Polls for the next window event.
  196.      *               The polling mode used is V_WAIT.
  197.      *                Therefore, VOloWinEventPoll does not
  198.      *               return until an event specified by
  199.      *               the mask is generated.
  200.      */
  201.     location = VOloWinEventPoll (V_WAIT);
  202.  
  203.     /*
  204.      *  VOloScreen:   Get's the location object's screen object
  205.      *  VOscSelect:   Selects screen as the current output device
  206.      *
  207.      *  Set the current screen from the location object. The
  208.      *  current screen will be NULL if the location object pertains
  209.      *  to a DataViews widget input object. The DataViews event type
  210.      *  for a widget input object would be V_NON_DV_WINDOW_EVENT.
  211.      */
  212.     current_screen = VOloScreen (location);
  213.     if (current_screen)
  214.       VOscSelect (current_screen);
  215.  
  216.     /*
  217.      *  VOloType:  returns the type of event.  These types
  218.      *             match event types specified in VOscWinEventMask.
  219.      */
  220.     switch (VOloType (location))
  221.       {
  222.  
  223.       case V_EXPOSE:
  224.         /*
  225.          *  VOloRegion:  Returns a rectangle representing the
  226.          *               exposed region on the screen.
  227.          *  TscRedraw:   After erasing, redraws all the drawports
  228.          *               in the screen.
  229.          *  A portion of the window has been exposed and needs
  230.          *  to be redrawn.
  231.          */
  232.         TscRedraw (current_screen, VOloRegion (location));
  233.         break;
  234.  
  235.       case V_RESIZE:
  236.         /*
  237.          *  The window size has been changed.
  238.          *  TscReset:  Resets all screen drawports after
  239.          *             window resizing
  240.          *  GRaspect_ratio:  Gets the size of the screen in pixels
  241.          *
  242.          *  Print the new size of the window to standard output.
  243.          */
  244.         TscReset (current_screen);
  245.         GRaspect_ratio (&screenx, &screeny);
  246.         printf ("Window Size:  %d %d\n", screenx, screeny);
  247.         break;
  248.  
  249.       case V_WINDOW_QUIT:
  250.         /*
  251.          * User requests a window quit.
  252.          * Print message for quitting after V_WINDOW_QUIT
  253.          */
  254.         printf ("User Selected Window Quit...\n");
  255.         Quit = YES;
  256.         break;
  257.  
  258.       case V_KEYPRESS:
  259.         /*
  260.          *  Check key selected.
  261.          *  VOloKeySym:  Returns the key symbol value of the
  262.          *               location object
  263.          *  If the key symbol represents the characters 'q'
  264.          *  or 'Q' then quit the program.
  265.          */
  266.         switch (VOloKeySym (location))
  267.           {
  268.           case 'q':
  269.           case 'Q':
  270.             Quit = YES;
  271.             break;
  272.  
  273.           default:
  274.             break;
  275.           }
  276.         break;
  277.  
  278.       case V_KEYRELEASE:
  279.       case V_BUTTONPRESS:
  280.       case V_BUTTONRELEASE:
  281.       case V_MOTIONNOTIFY:
  282.       case V_NON_DV_WINDOW_EVENT:
  283.         /*
  284.          *  VUerHandleLocEvent: Service the event.
  285.          *                      This routine will check if the
  286.          *                      event is used by any input objects
  287.          *                      that are in the view.
  288.          */
  289.         event_req_status = VUerHandleLocEvent (location);
  290.  
  291.         /*
  292.          *  TdpForEachDrawport:  Applies a function to all drawports,
  293.          *              in all screens.
  294.          *
  295.          *  If an input object used the event, then update the
  296.          *  current screen if one has been set otherwise update
  297.          *  the first screen.
  298.          */
  299.         if (event_req_status != INPUT_UNUSED)
  300.           if (current_screen)
  301.             TdpForEachDrawport ((TDPTRAVERSEFUNPTR)drawnext_if_screen, (ADDRESS) current_screen);
  302.           else
  303.             TdpForEachDrawport ((TDPTRAVERSEFUNPTR)drawnext_if_screen, (ADDRESS) screen[0]);
  304.         break;
  305.  
  306.       default:
  307.         break;
  308.  
  309.       }
  310.  
  311.     /*
  312.      *  VOloWinEventGet:   Returns the window event structure of
  313.      *                     the location object.
  314.      *  VUweReportEvent:   Reports window events at a specified
  315.      *                     level of detail. Level 3 reports
  316.      *                     information relevant to the event type.
  317.      *
  318.      *  To report window event information, rename the executable
  319.      *  image of "win_multi.x" to "win_multidb.x".  Invoke this
  320.      *  executable from the command line.
  321.      */
  322.     if (!strcmp (argv[0], WIN_MULTI_DBG))
  323.       {
  324.         we = (WINEVENT *) VOloWinEventGet (location);
  325.         VUweReportEvent (we, (int)3);
  326.         printf ("\n");
  327.       }
  328.  
  329.     /* exit the program */
  330.     if (Quit == YES)
  331.       break;
  332.   }
  333.  
  334.   /*--------------------
  335.    *   Termination
  336.    *
  337.    *   VOscSelect:   Selects screen as the current output device
  338.    *   TscErase:     Erase the entire screen in the default
  339.    *                 background color
  340.    *   TdpDestroy:   Destroy the drawport,
  341.    *   TviDestroy:   Destroy the view, freeing the allocated memory
  342.    *   TscClose:     Closes a screen object's assoc. display device
  343.    *   TTerminate:   Perform the clean-up for DV-Tools
  344.    */
  345.   printf ("Quitting...\n");
  346.   for (i = 0; i < MAXWINS; i++)
  347.     {
  348.       VOscSelect (screen[i]);
  349.       TscErase (screen[i]);
  350.       TdpDestroy (drawport[i]);
  351.       TviDestroy (view[i]);
  352.       TscClose (screen[i]);
  353.     }
  354.   TTerminate ();
  355.   return EXIT_OK;
  356. }
  357.  
  358. /*---------------------
  359.  *
  360.  *    drawnext_if_screen -- Update dynamics for all drawports
  361.  *                associated with the passed screen object.
  362.  */
  363. /* ARGSUSED */
  364. LOCAL ADDRESS 
  365. drawnext_if_screen (drawport, screen)
  366.      DRAWPORT drawport;
  367.      ADDRESS screen;
  368. {
  369.   /*
  370.    *  TdpGetScreen:  Gets the screen object of a drawport
  371.    *  TdpDrawNext:   Updates all dynamic objects within a
  372.    *             drawport's view
  373.    *
  374.    *  If the screen object associated with this drawport matches
  375.    *  the screen object passed in then updated the dynamics of this
  376.    *  drawport.
  377.    */
  378.   if ( (OBJECT)screen == TdpGetScreen (drawport))
  379.     TdpDrawNext (drawport);
  380.  
  381.   return V_CONTINUE_TRAVERSAL;
  382. }
  383.